thread
This module provides low-level primitives for working with multiple
threads (a.k.a. light-weight processes or tasks) — multiple
threads of control sharing their global data space. For
synchronization, simple locks (a.k.a. mutexes or binary
semaphores) are provided.
The module is optional and supported on SGI IRIX 4.x and 5.x and Sun
Solaris 2.x systems, as well as on systems that have a PTHREAD
implementation (e.g. KSR).
It defines the following constant and functions:
Lock objects have the following methods:
Caveats:
- Threads interact strangely with interrupts: the
KeyboardInterrupt exception will be received by an arbitrary
thread.
- Calling sys.exit(status) or executing
raise SystemExit, status is almost equivalent to calling
thread.exit_prog(status), except that the former ways of
exiting the entire program do honor finally clauses in the
current thread (but not in other threads).
- Not all built-in functions that may block waiting for I/O allow other
threads to run, although the most popular ones (sleep,
read, select) work as expected.